package com.nj.dms.bean;

/**
 * 分页类
 * 
 * @author 203
 *
 */
public class PageBean {
	/**
	 * 当前页
	 */
	private int curPage;
	/**
	 * 下页
	 */
	private int nextPage;
	/**
	 * 上页
	 */
	private int prePage;
	/**
	 * 每页显示的最大记录数
	 */
	private int maxSize;
	/**
	 * 总页数
	 */
	private int pageCnt;
	/**
	 * 查询的记录数
	 */
	private long recordCnt;

	public int getCurPage() {
		return curPage;
	}

	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}

	public int getNextPage() {
		return nextPage;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	public int getPrePage() {
		return prePage;
	}

	public void setPrePage(int prePage) {
		this.prePage = prePage;
	}

	public int getMaxSize() {
		return maxSize;
	}

	public void setMaxSize(int maxSize) {
		this.maxSize = maxSize;
	}

	public int getPageCnt() {
		return pageCnt;
	}

	public void setPageCnt(int pageCnt) {
		this.pageCnt = pageCnt;
	}

	public long getRecordCnt() {
		return recordCnt;
	}

	public void setRecordCnt(long recordCnt) {
		this.recordCnt = recordCnt;
	}

	/**
	 * 初始化分页数据
	 * 
	 * @param curPage
	 * @param maxSize
	 * @param recordCnt
	 */
	public void init(int curPage, int maxSize, int recordCnt) {
		this.curPage = curPage;
		this.maxSize = maxSize;
		this.recordCnt = recordCnt;

		// 计算总页数
		this.pageCnt = (int) (recordCnt / maxSize + (recordCnt % maxSize == 0 ? 0 : 1));

		// 计算上页 下页
		update(curPage);
	}

	/**
	 * 计算上页 下页
	 * 
	 * @param curPage2
	 */
	private void update(int curPage) {
		// 计算上页
		if (curPage > 1) {
			this.prePage = curPage - 1;
		} else {
			this.prePage = 1;
		}

		// 计算下页
		if (curPage < this.pageCnt) {
			this.nextPage = curPage + 1;
		} else {
			this.nextPage = this.pageCnt;
		}
	}

}
